package com.lyl.exception.common;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.Collections;
import java.util.List;

@Data
@Accessors(chain = true)
@NoArgsConstructor
public class Result {
    public static final List EMPTY_LIST = Collections.EMPTY_LIST;

    private Integer code;
    private String msg;
    private Object data = EMPTY_LIST;

    public Result( Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Result success() {
        return build(ResultCode.SUCCESS);
    }

    public static Result success(Object data){
        return build(ResultCode.SUCCESS)
                .setData(data);
    }

    public static Result fail(Integer code,String msg){
        return new Result(code,msg,EMPTY_LIST);
    }

    public static Result fail(){
        return build(ResultCode.FAIL);
    }

    public static Result fail(ResultCode resultCode){
        return build(resultCode);
    }

    public static Result build(ResultCode resultCode){
        return new Result(resultCode.getCode(),resultCode.getMsg(),EMPTY_LIST);
    }



}
